home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-12-10 | 10.6 KB | 425 lines | [TEXT/ALFA] |
- ## -*-Tcl-*- (install)
- # ###################################################################
- # Alpha - new Tcl folder configuration
- #
- # FILE: "ftpMenu.tcl"
- # created: 20/7/96 {6:02:55 pm}
- # last update: 8/10/97 {6:19:26 pm}
- #
- # Description:
- #
- # ###################################################################
- ##
-
- alpha::menu ftpMenu 0.1 "•141" in_menu {} uninstall {this-file} \
- help {[editMark "$HOME:Help:Alpha Manual" "Ftp Browser" -r]}
-
- hook::register savePostHook ftpPostHook
-
- proc ftpMenu {} {}
-
- proc ftpPostHook {name} {
- global fetched
- if {[info exists fetched($name)]} {
- set specs $fetched($name)
- message "Updating '[file tail $name]' on [car $specs]…"
- if {[string length [cadr $specs]]} {
- ftpStore $name [car $specs] "[cadr $specs]/[file tail $name]" [caddr $specs] [cadddr $specs]
- } else {
- ftpStore $name [car $specs] "[file tail $name]" [caddr $specs] [cadddr $specs]
- }
- }
- }
-
- proc rebuildFtpMenu {} {
- global savedMounts recentMounts ftpMenu useCache
-
- menu -n $ftpMenu -p ftpMenuProc {
- help
- "(-"
- "<S/ibrowse…"
- "<S/i<IbrowseCurrent…"
- "/nbrowseMounts…"
- "(-"
- addMountPoint…
- makePermanent…
- removeMountPoint…
- saveAsAt…
- "(-"
- useCache
- flushCache
- "(-"
- "createFileset"
- "(-"
- }
- markMenuItem -m $ftpMenu "Use Cache" $useCache
- if {[info exists savedMounts]} {
- foreach m [lsort -ignore [array names savedMounts]] {
- addMenuItem -m -l "b " $ftpMenu $m
- }
- }
- if {[info exists recentMounts]} {
- addMenuItem -m $ftpMenu "(-"
- foreach m [lsort -ignore [array names recentMounts]] {
- addMenuItem -m -l "b " $ftpMenu $m
- }
- }
- }
-
- if {![info exists useCache]} {set useCache 1}
-
- app::registerMultiple ftp [list Arch FTCh] [list •141 •315] rebuildFtpMenu
-
- proc mountPoints {} {
- global savedMounts recentMounts
- if {[info exists recentMounts]} {
- if {[info exists savedMounts]} {
- set l [concat [array names recentMounts] [array names savedMounts]]
- } else {
- set l [array names recentMounts]]
- }
- } else {
- set l [array names savedMounts]
- }
- return [lsort $l]
- }
-
-
-
- proc ftpMenuProc {menu item} {
- global modifiedVars modifiedArrVars savedMounts recentMounts PREFS fetched HOME ftpMenu useCache createFtpType
- switch $item {
- help {editMark "$HOME:Help:Alpha Manual" "Ftp Browser" -r}
- browse {eval ftpBrowse [lrange [getLogin {Browse remote machine:} 0] 0 3]}
- browseCurrent { if {[info exists fetched([win::Current])]} {
- eval ftpBrowse $fetched([win::Current])
- } else {
- beep; message "'[win::CurrentTail]' not from remote host."
- }}
- browseMounts {
- set l [mountPoints]
- set res [listpick -p "Mount point:" $l]
- if {[info exists recentMounts($res)]} {
- eval ftpBrowse $recentMounts($res)
- } else {
- eval ftpBrowse $savedMounts($res)
- }
- }
-
- addMountPoint { addMountPoint }
- makePermanent { makeMountPermanent }
- createFileset { ftpCreateFileset }
- removeMountPoint {
- set pt [listpick -p "Remove which mount point?" [lsort -ignore [array names savedMounts]]]
- unset savedMounts($pt)
- removeArrDef savedMounts $pt
- rebuildFtpMenu
- }
- saveAsAt {
- global fetched PREFS
- set name [prompt "Name:" [win::CurrentTail]]
- set point [listpick -p "At which mount point?" [mountPoints]]
- if {[info exists recentMounts($point)]} {
- set specs $recentMounts($point)
- } else {
- set specs $savedMounts($point)
- }
- set name "$PREFS:ftptmp:$name"
- set fetched($name) $specs
- message "Saving '$name' on [car $specs]…"
-
- if {![file exists $name]} {
- set fid [open $name w]
- close $fid
- }
- saveAs -f "$name"
-
- set num 0
- set pathname [cadr $specs]
- for {set i [expr [string length $pathname] - 1]} {$i >= 0} {incr i -1} {
- scan $pathname "%c" char
- incr num $char
- }
-
- set nm "$PREFS:ftptmp:listing.$num"
- catch {rm $nm}
-
- setWinInfo platform $createFtpType
- setWinInfo dirty 1
- save
- }
-
- setDefaults {
- global ftpDefaults modifiedVars
- set ftpDefaults [lrange [getLogin "Enter defaults that you wish saved:" 0] 0 3]
- lappend modifiedVars ftpDefaults
- }
- flushCache { rm "$PREFS:ftptmp:*"; [catch {unset recentMounts}]; rebuildFtpMenu }
- useCache {
- set useCache [expr 1 - $useCache]
- markMenuItem -m $ftpMenu "Use Cache" $useCache
- lappend modifiedVars useCache
- }
- default {
- if {[info exists recentMounts($item)]} {
- eval ftpBrowse $recentMounts($item)
- } else {
- eval ftpBrowse $savedMounts($item)
- }
- }
- }
- }
-
-
- proc ftpFilesetOpen {menu item} {
- global gfileSets PREFS fetched fileSetsExtra
-
- if {[set ind [lsearch $gfileSets($menu) "*$item"]] >= 0} {
- set f [lindex $gfileSets($menu) $ind]
- set lnm [file tail $f]
- regsub -all {:} $f {/} f
- set nm "$PREFS:ftptmp:$lnm"
- set specs $fileSetsExtra($menu)
- if {![file exists $nm]} {
- ftpFetch $nm [car $specs] $f [caddr $specs] [cadddr $specs]
- }
- edit -w $nm
- set fetched($nm) $specs
- }
- }
-
-
- proc ftpCreateFileset {} {
- global gfileSets gfileSetsType PREFS fileSetsExtra
-
- set specs [getLogin]
- set name [car $specs]
- set host [cadr $specs]
- set path [caddr $specs]
- set user [cadddr $specs]
- set password [caddddr $specs]
- set pattern "^[prompt {Name pattern?} {.*.[ch]}]$"
- set path [string trimright $path {/}]
-
- set fileSetsExtra($name) [list $host $path $user $password]
-
- if { ![file exists "$PREFS:ftptmp:"] } {
- mkdir "$PREFS:ftptmp:"
- }
- set nm "$PREFS:ftptmp:listing.$path"
- ftpList $nm $host $path $user $password
- set files {}
- foreach f [processListing $nm] {
- if {![string match {*/} $f] && [regexp $pattern $f]} {
- lappend files "$path/$f"
- }
- }
- regsub -all {/} $files {:} files
-
- global gfileSets gfileSetsType
- set gfileSets($name) [lsort -command sortByTail $files]
- set gfileSetsType($name) ftp
- if {[askyesno "Save project fileset?"] == "yes"} {
- addArrDef gfileSetsType $name ftp
- addArrDef gfileSets $name $gfileSets($name)
- addArrDef fileSetsExtra $name $fileSetsExtra($name)
- }
- return $name
- }
-
-
- proc processListing {path} {
- set fd [open $path "r"]
- set lines [split [read $fd] "\n"]
- close $fd
- set files {}
- foreach f [cdr [lreplace $lines end end]] {
- set nm [lindex $f end]
- if {[string length $nm]} {
- if {[string match "d*" $f]} {
- lappend files "$nm/"
- } else {
- lappend files $nm
- }
- }
- }
- return $files
- }
-
- proc getLogin {{prompt {All but 'password' are required:}} {nm 1}} {
- global ftpDefaults
- if {[info exists ftpDefaults]} {
- set defs $ftpDefaults
- } else {
- set defs {"" "" "" ""}
- }
- set left 10
- set right 100
- set top 10
- set bottom 30
- set eleft [expr $left + 100]
- set eright 370
- set incr 30
-
- set height 198
-
- if $nm {incr height $incr}
- set l "dialog -w 400 -h $height -t [list $prompt] $left $top 400 $bottom"
-
- if {$nm} {
- incr top $incr
- incr bottom $incr
- lappend l -t {Name:} $left $top $right $bottom
- lappend l -e {} $eleft $top $eright $bottom
- }
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Host:} $left $top $right $bottom
- lappend l -e [car $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Path:} $left $top $right $bottom
- lappend l -e [cadr $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {UserID:} $left $top $right $bottom
- lappend l -e [caddr $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Password:} $left $top $right $bottom
- lappend l -e [cadddr $defs] $eleft [expr $top + 6] $eright [expr $bottom - 12]
-
- incr top [expr $incr + 10]
- incr bottom [expr $incr + 10]
- lappend l -b "OK" $left $top $right [expr $top + 20]
- lappend l -b "Cancel" [expr $left + 200] $top [expr $right + 200] [expr $top + 20]
-
- set res [eval "$l"]
- if {[lindex $res end]} {error "Cancel"}
- return $res
- }
-
-
- proc addMountPoint {} {
- global savedMounts modifiedArrVars
-
- set res [getLogin]
- if {[lindex $res 5]} {
- set savedMounts([car $res]) [lrange $res 1 4]
- lappend modifiedArrVars savedMounts
- rebuildFtpMenu
- }
- }
-
-
- proc makeMountPermanent {} {
- global recentMounts savedMounts modifiedArrVars
- if {![info exists recentMounts]} {
- alertnote "You have no temporary mounts."
- return
- }
- set res [listpick -p "Make which temporary mount point permanent?" [lsort [array names recentMounts]]]
- set name [prompt "Name?" $res]
- set savedMounts($name) $recentMounts($res)
- unset recentMounts($res)
- lappend modifiedArrVars savedMounts
- rebuildFtpMenu
- }
-
-
- proc ftpPromptBrowse {} {
- eval ftpBrowse [lrange [getLogin {Browse remote machine:} 0] 0 3]
- }
-
- proc ftpBrowse {host dir user password {fname {}}} {
- global PREFS fetched lastFtpDir recentMounts savedMounts useCache
-
- watchCursor
- if {![string length $password]} {
- set password [getPassword $host]
- }
-
- if {![file exists "$PREFS:ftptmp"]} {
- mkdir "$PREFS:ftptmp"
- }
- if {$dir == {-}} {
- if {![info exists lastFtpDir] || ![string length $lastFtpDir]} {set lastFtpDir ""}
- set dir [prompt "'$host' dir:" $lastFtpDir]
- }
- set dir [string trimright $dir {/}]
- set lastFtpDir $dir
-
- set num 0
- for {set i [expr [string length $dir] - 1]} {$i >= 0} {incr i -1} {
- scan $dir "%c" char
- incr num $char
- }
-
- set nm "$PREFS:ftptmp:listing.$num"
-
- if {!$useCache || ![file exists $nm]} {
- ftpList $nm $host $dir $user $password
- }
- if {[catch {processListing $nm} listing]} {
- alertnote "Error fetching directory '$dir'"
- error "Error fetching directory '$dir'"
- }
- set files [concat {..} $listing]
- if {$fname != ""} {
- set file [listpick -L $fname -p "$dir/" $files]
- } else {
- set file [listpick -p "$dir/" $files]
- }
-
- if {$file == {..}} {
- if {[regexp {((/|\w)+)/\w+} $dir dummy sub]} {
- return [ftpBrowse $host $sub $user $password]
- } else {
- return [ftpBrowse $host "" $user $password]
- }
- }
-
- if {[string match {*/} $file]} {
- if {[string length $dir]} {
- return [ftpBrowse $host [string trimright "$dir/$file" {/}] $user $password]
- } else {
- return [ftpBrowse $host [string trimright "$file" {/}] $user $password]
- }
- }
-
- set entry [list $host $dir $user $password]
- set new 1
- foreach name [array names savedMounts] {
- if {([car $savedMounts($name)] == [car $entry]) && ([cadr $savedMounts($name)] == [cadr $entry])} {
- set new 0
- break;
- }
- }
- if $new {
- set recentMounts($dir) $entry
- rebuildFtpMenu
- }
-
- set nm "$PREFS:ftptmp:$file"
- if {!$useCache || ![file exists $nm]} {
- if {[string length $dir]} {
- ftpFetch $nm $host "$dir/$file" $user $password
- } else {
- ftpFetch $nm $host "$file" $user $password
- }
- }
- edit -w $nm
- set fetched($nm) [list $host $dir $user $password]
- }
-
- proc getPassword {host} {
- set values [dialog -w 300 -h 90 -t "Password for $host:" 10 20 290 30 \
- -e "" 10 40 290 42 -b OK 20 60 85 80 -b Cancel 105 60 170 80]
- if {[lindex $values 2]} {error "Cancel"}
- return [string trim [lindex $values 0]]
- }
-